using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;

namespace produccion.clases
{

   public  class CLSORDORDD : ObservableObject
    {

MDOgeneral mod = new MDOgeneral();

#region metodos
        
       public int insertar() {
        try {
            string query = "insert into ordordd (NROORDD_OOD,NROORDP_OOD,CODREF_OOD,CODCOL_OOD,CODTAL_OOD,CANPRO_OOD) values ('"+NROORDD_OOD+"','"+NROORDP_OOD+"','"+CODREF_OOD+"','"+CODCOL_OOD+"','"+CODTAL_OOD+"',"+CANPRO_OOD+")";
            return mod.comando(query);
        }
        catch (Exception ex) { throw ex; }
        }

       public int actualizar() {
        try {
            string query = "update ordordd set CANPRO_OOD=" + CANPRO_OOD + " where NROORDD_OOD='" + NROORDD_OOD + "' and NROORDP_OOD='" + NROORDP_OOD + "' and CODREF_OOD='" + CODREF_OOD + "' and CODCOL_OOD='" + CODCOL_OOD + "' and CODTAL_OOD='" + CODTAL_OOD + "'";
            return mod.comando(query);
        }
        catch (Exception ex) { throw ex; }
        }

       public Boolean existe() {
        try {
            string query = "select count(*) from ordordd where NROORDD_OOD='" + NROORDD_OOD + "' and NROORDP_OOD='" + NROORDP_OOD + "' and CODREF_OOD='" + CODREF_OOD + "' and CODCOL_OOD='" + CODCOL_OOD + "' and CODTAL_OOD='" + CODTAL_OOD + "'";
            DataTable val = mod.consulta(query);
            if (val.Rows.Count > 0) {
                if (Convert.ToUInt32(val.Rows[0][0])>0) {
                    return true;
                }
            }
            return false;
        }
        catch (Exception ex) { throw ex; }
        }

       public List<CLSORDORDD> consultar()
       {
           try {

               string query = "select nroordd_ood, nroordp_ood,codref_ood,codcol_ood,codtal_ood, canpro_ood from ordordd where nroordd_ood='" + NROORDD_OOD + "' order by codref_ood,codcol_ood,codtal_ood";
               DataTable val = mod.consulta(query);
               List<CLSORDORDD> lista = new List<CLSORDORDD>();
               foreach (DataRow dr in val.Rows) {
                   lista.Add(new CLSORDORDD {
                       NROORDP_OOD = dr["NROORDP_OOD"].ToString(),
                       NROORDD_OOD = dr["NROORDD_OOD"].ToString(),
                       CODTAL_OOD = dr["CODTAL_OOD"].ToString(),
                       CODREF_OOD = dr["CODREF_OOD"].ToString(),
                       CODCOL_OOD = dr["CODCOL_OOD"].ToString(),
                       CANPRO_OOD = Convert.ToInt32(dr["CANPRO_OOD"])
                   });
               }
               return lista;
           }
           catch (Exception ex) {throw ex;}       
       }
        
#endregion

#region propiedades
                
        string _NROORDD_OOD;
        public string NROORDD_OOD{
        get{return _NROORDD_OOD;}
            set{_NROORDD_OOD=value;
            RaisePropertyChangedEvent("NROORDD_OOD");
            }
        }

        string _NROORDP_OOD;
        public string NROORDP_OOD{
        get{return _NROORDP_OOD;}
            set{_NROORDP_OOD=value;
            RaisePropertyChangedEvent("NROORDP_OOD");
            }
        }

        string _CODREF_OOD;
        public string CODREF_OOD{
            get{return _CODREF_OOD;}
            set{ _CODREF_OOD=value;
            RaisePropertyChangedEvent("CODREF_OOD");
            }
        }

        string _CODCOL_OOD;
        public string CODCOL_OOD{
            get{return _CODCOL_OOD;}
            set{ _CODCOL_OOD=value;
            RaisePropertyChangedEvent("CODCOL_OOD");
            }
        }

        string _CODTAL_OOD;
        public string CODTAL_OOD{
            get{return _CODTAL_OOD;}
            set{ _CODTAL_OOD=value;
            RaisePropertyChangedEvent("CODTAL_OOD");
            }
        }

        int _CANPRO_OOD;
        public int CANPRO_OOD{
            get{return _CANPRO_OOD;}
            set{ _CANPRO_OOD=value;
            RaisePropertyChangedEvent("CANPRO_OOD");
            }
        }
        
#endregion

    }
}
